<?php 


	$dsn = "mysql: host=localhost;dbname=thinksiteshop;charset=utf8";
	$pdo = new PDO($dsn,"root","root");


	$sql = "select * from tk_new";
	$stat = $pdo->query($sql);
  	//分页效果
  	$total =$stat->rowCount();//总记录数
  	$page = 1;//当前页
  	// 每页记录数
	$every = 1;
	$pages = ceil($total/$every);//总页数
   //判断有没有点击上一页或者下一页
  	if(isset($_GET['page'])){
  		//当前页就是闯过的page的值
  		$page = $_GET['page'];
  	}
  	//当前页如果大于总页数就等于当前页
  	if($page > $pages){
  		$page = $pages;
  	}
  	//当前页小于1时就等于第一页
  	if($page < 1){
  		$page = 1;
  	}// 计算每页的limit的起始位置
  	$start = ($page-1) * $every;
  	$sql.= " limit {$start},$every";
  	 $res = $pdo->query($sql);
  	 $rs=$res->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE HTML >
<html>
 <head>
  <title> 用户中心 </title>
  <meta charset="utf-8">
  <style>
	*{margin:0px;padding:0px}
	table{margin:20px auto}
	.so{width:400px;margin:30px auto}
	.so div{height:40px;line-height:40px}
	.so div span{display:inline-block;width:80px}
	input[name=sub]{width:105px;height:30px}
  </style>
 </head>

 <body>
	<table border=1 cellspacing=0 width="600px">
		<tr height="40px" align="center">
			<td width="7%">编号</td>
			<td width="12%">标题</td>
			<td width="7%">时间</td>
			<td width="20%">作者</td>
			<td width="20%">描述</td>
		</tr>
		<?php foreach($rs as $vo){?>
		<tr align="center" height="40px">
			<td><?=$vo['nid'] ?></td>
			<td><?=$vo['title'] ?></td>
			<td><?=$vo['ntime']?></td>
			<td><?=$vo['author'] ?></td>
			<td><?=$vo['descp'] ?></td>
		</tr>
		<?php };?>
		<tr height="40px" align="center">
			<td colspan=6>
				<a href="./frist.php?page=<?= ($page-1).(isset($url)?$url:"")?>">上一页</a>&nbsp;&nbsp;
				第<?=$page?>页/共<?=$pages ?>页&nbsp;&nbsp;
				<a href="./frist.php?page=<?= ($page+1).(isset($url)?$url:"")?>">下一页</a>
			</td>
		</tr>
	</table>
 </body>
</html>


